<?
/*
		topGames: an iRC games bot
		Copyright (C) 2008 Marcos García <marcosgdf@gmail.com>
    
		This file is part of topGames

		This program is free software: you can redistribute it and/or modify
		it under the terms of the GNU General Public License as published by
		the Free Software Foundation, either version 3 of the License, or
		any later version.

		This program is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		GNU General Public License for more details.

		You should have received a copy of the GNU General Public License
		along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

define('MASTER_DIR',dirname(__FILE__).'/'); //define the master dir
define('LOG_DIR',MASTER_DIR.'logs/'); //define the log dir
define('TOPGAMES_VERSION','0.4.1 Beta');
require(MASTER_DIR.'class/class.misc.php');
require(MASTER_DIR.'config.php');
require(MASTER_DIR.'class/class.const.php');
require(MASTER_DIR.'class/class.raw.php');
require(MASTER_DIR.'class/class.juegos.php');
require(MASTER_DIR.'class/class.events.php');
require(MASTER_DIR.'class/class.sockets.php');

$tg = new topgames;
global $_CFG;

echo "\n";
echo "------------------------------\n";
echo "topGames ".TOPGAMES_VERSION." by Marcos García\n";
echo "http://www.topgames.com.es http://topgames.googlecode.com <marcosgdf@gmail.com>\n";
echo "------------------------------\n";

if (LOG_STATUS) { //checks if logging is enabled
	$tg->openLog();
	if (in_array('status',$_CFG["LOG_REC"])) $tg->writeLog("Bot iniciado");
}

$pidfd = fopen(MASTER_DIR.'topgames_'.BOT_NUMBER.'.pid',"w"); //opens the .pid file
if ($pidfd) {
	$pid = getmypid();
	fwrite($pidfd,$pid); //writes the pid in the .pid file
	fclose($pidfd);
}
else {
    $message = 'Error al intentar crear el archivo topgames_'.BOT_NUMBER.'.pid';
	if (LOG_STATUS && (in_array('status', $_CFG['LOG_REC']))) $tg->writeLog($message);
	echo "[-] $message\n";
}

$tg->doCheck(); //checks if all is allright
initConnect($tg); //starts the process to open an iRC connection
?>